<?php 
	namespace Admin\Controller;
	use Think\Controller;

	class NoticeController extends Controller
	{
		// 查看
		public function index()
		{
			$notice = M('notice');

			$list = $notice->select();
			$this->assign('list',$list);
			$this->display();
		}

		// 执行添加
		public function doadd()
		{
			$notice = M('notice');

			// 判断是否为空
			if(empty(I()['content'])){
				$this->success('公告内容不能为空');
				exit;
			}

			if($notice->add(I())){
				$this->success('公告添加成功',U('Notice/index'));
			}else{
				$this->error('公告添加失败');
			}

		
		}

		// 删除
		public function del()
		{
			$notice = M('notice');
												
			if($notice->delete(I()['id']) > 0){
				$this->success('公告删除成功',U('Notice/index'));
			}else{
				$this->error('公告删除失败');
			}
		}

		// 修改的内容
		public function edit()
		{	
			$id = I()['id'];
			$notice = M('notice');
			$edit = $notice->where("id=$id")->find();
			$this->assign('vo',$edit);
			$this->display();
		}

		// 执行修改的内容
		public function doedit()
		{
			$notice = M('notice');

			if($notice->save(I()) > 0){
				$this->success('修改成功',U('Notice/index'));
			}else{
				$this->error('修改失败');
			}
		}

	}
	